#!/bin/bash
CUR_DIR=`pwd`
set -e
if ! type cmake >/dev/null 2>&1;then
    make -j 4
else
    mkdir -p build
    #rm -rf lib/*
    cd build && rm -f CMakeCache.txt
    ORG_LANG=$LANG
    LANG="en_US.UTF-8"
    GIT_VER=`git log -1 | grep commit | awk '{print $2}'`
    BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
    CMP_TIME=`date +%Y%m%d.%H.%M.%S`
    export LANG=$ORG_LANG
    export GIT_VER=$BRANCH":"$GIT_VER
    export CMP_TIME=$CMP_TIME
    cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES .. && make -j 
fi

## ubuntu default shell is dash, not support array
# BIN_ARR=("Client" "MsgTransInThread" "Server" "Timer" "UserDefineThread")
# for (( i=0;i<${#BIN_ARR[@]};i++ )) do
#     #${#array[@]}获取数组长度用于循环
#     mkdir -p $CUR_DIR/examples/${BIN_ARR[i]}/bin
#     cd $CUR_DIR/examples/${BIN_ARR[i]}/bin 
#     ln -sf ../../../bin/T${BIN_ARR[i]} T${BIN_ARR[i]}
# done
#CodeChecker parse --export html --output ./reports_html .codechecker/reports/
cd $CUR_DIR
for exe_dir in `ls examples |grep -v CMakeLists.txt`
do 
    mkdir -p $CUR_DIR/examples/${exe_dir}/bin
    cd $CUR_DIR/examples/${exe_dir}/bin 
    ln -sf ../../../bin/T${exe_dir} T${exe_dir}
done
